import React, { Component } from 'react'
import { withRouter, Route } from 'react-router-dom'
import queryString from 'query-string'
import styles from './Content.module.scss'
import Crumbs from './common/Crumbs'
import OrgDetail from '../router/OrgDetail'
import Activity from './../router/Company/Activity'
import CommonDetail from './../components/common/CommonDetail'
import { RouteWithSubRoutes, compantyRoutes } from '../router'
import './CompanyContent.css'
import { backTop } from './../util/index'

export default withRouter(class CompantyContent extends Component {


  goBackTop() {
    backTop()
  }

  goHome() {
    this.props.history.replace('/mainPage/main')
  }

  render() {
    const { location, match } = this.props;
    const oSearch = queryString.parse(location.search);
    const pageType = match.params.orgType;
    const compantyRoute = compantyRoutes.filter(item => location.pathname === item.path || `/org/${pageType}` === item.path )[0];
    const orgName = compantyRoute? compantyRoute.title : '';
    const crumbsList = [{
      name : '智库联盟',
      path : '/mainPage/org',
    },{
      name : '单位首页',
      path : '/org/main?orgId=' + oSearch.orgId,
    },{
      name : orgName,
      path : '',
    }];
    if( location.pathname.includes(`/org/${pageType}/pageDetail`) ){
      crumbsList[2].path = location.pathname + '?orgId=' + oSearch.orgId;
      crumbsList.push({
        name : '详情'
      });
    };
    if( location.pathname.includes(`/org/${pageType}/orgDynamicList`) ){
      crumbsList[2].path = location.pathname + '?orgId=' + oSearch.orgId;
      crumbsList.push({
        name : '动态列表'
      });
    };

    return (
      <div className={styles.content}>
        <Crumbs list={crumbsList} />
        {/* <div className={styles.companty_postion}>
          当前位置：智库联盟 > 研究成果 > <span>内部报告</span>
        </div> */}
        {compantyRoutes.map((route, i) => (
          <RouteWithSubRoutes key={i} {...route} />
        ))}
        {/* 机构主页 - 详情 */}
        <Route path='/org/:pageType/pageDetail/:id' component={OrgDetail} />

        {/* 机构动态列表 */}
        <Route path='/org/:pageType/orgDynamicList/:id' component={Activity} />

        <div className="go_to_top">
          <div className="backBg" onClick={() => this.goHome()}>
            返回首页
          </div>
          <div className="backBg" onClick={() => this.goBackTop()}>
            返回顶部
          </div>
        </div>
      </div>
    )
  }
})